package fausto 
{
	import com.greensock.TweenMax;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	/**
	 * ...
	 * @author Ben.
	 */
	public class Menu extends Sprite
	{
		public var _open:Boolean = false;
		
		private var _i:Infos
		private var _mi:MenuItem
		private var _tabM:Array
		
		private var _seletectedItem:MenuItem
		
		public function Menu() 
		{
			addEventListener(Event.ADDED_TO_STAGE, onStaged);
			_i = Infos.getInstance();
		}
		
		private function onStaged(e:Event):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, onStaged);			
		}
		
		public function createMenu():void
		{
			var xInit:Number = 0;
			
			_tabM = new Array();
			
			for (var i:int = 0; i < _i.theXML.part.length(); i++)
			{
				if (i == 1)
				{
					_mi = new MenuItem(_i.theXML.part[i].label, i, true);
					_seletectedItem = _mi;
				}
				else
				{
					_mi = new MenuItem(_i.theXML.part[i].label, i);
				}
				
				_mi.x = xInit;
				_mi.y = 12;
				addChild(_mi);
				xInit += _mi.width + 20;
				_tabM.push(_mi);
			}
			
			addEventListener("MENU_CLICK", manageMenu);
		}
		
		private function manageMenu(e:Event):void 
		{
			_seletectedItem.selected = false;
			_seletectedItem = e.target as MenuItem;
		}
		
		public function closeMenu():void 
		{
			_open = false;
			TweenMax.to(this, 0.4, { y:stage.stageHeight - 5 } );
		}
		
		public function openMenu():void 
		{
			_open = true;
			TweenMax.to(this, 0.4, { delay:0.2, y:stage.stageHeight - 50 } );
		}
		
	}

}